<?php

namespace web\api\controller;

use addons\member\model\FeedbackModel;

/**
 * Description of Contact
 * 联系客服
 */
class Feedback extends UserBase{
	/**
     * 反馈列表
     */
    public function ContactList(){
    	try {
            $feedbackModel = new FeedbackModel;
	        $filter = " user_id = $this->user_id ";
	        $list = $feedbackModel->getDataList($this->getPageIndex(),$this->getPageSize(),$filter, '*','create_time asc');
	        return $this->successJSON($list);
	    } catch (\Exception $ex) {
	        return $this->failJSON($ex->getMessage());
	    }
    }
    
    /**
     * 详细回复查看
     */
    public function details(){
        $feedbackModel = new FeedbackModel;
    	try {
	        $id = $this->_post('id');
	        $data = $feedbackModel->field('id,content,create_time,reply_content,reate_time,state')->where('id',$id)->find();
	        return $this->successJSON($data);
	    } catch (\Exception $ex) {
	        return $this->failJSON($ex->getMessage());
	    }
    }

    /**
     * 是否解决
     */
    public function is_solve(){
        $feedbackModel = new FeedbackModel;
    	try {
    		//话题ID
    		$id = $this->_post('id');
		    $data['state'] = $this->_post('state')==2?2:3;
            $res = $feedbackModel->save($data,['id'=>$id]);
            if(!$res) $this->failJSON('操作失败');
	        return $this->successJSON();
	    } catch (\Exception $ex) {
            $feedbackModel->rollback();
	        return $this->failJSON($ex->getMessage());
	    }
    }

    /**
     * 发起反馈
     */
    public function add_Contact(){
        $feedbackModel = new FeedbackModel;
    	try {
		    $data['user_id'] = $this->user_id;
		    $data['content'] = $this->_post('content');
//		    $data['type'] = $this->_post('type');
//		    $data['image'] = $this->_post('image');
		    $data['create_time'] = NOW_DATETIME;
		    $data['state'] = '0';
		    if ($data['content'] == '') {
		    	return $this->failJSON(lang('FEEDBACK_MSG'));
		    }
            $feedbackModel->add($data);
	        return $this->successJSON();
	    } catch (\Exception $ex) {
            $feedbackModel->rollback();
	        return $this->failJSON($ex->getMessage());
	    }
    }

    
}
